package tas.co.in.controller.codeInfo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import tas.co.in.dao.codeInfo.CodeInfo;
import tas.co.in.domain.codeInfo.CodeInfoBean;

public class CodeInfoController extends MultiActionController
{
	private CodeInfo codeInfo;

	public void setCodeInfo(CodeInfo codeInfo) 
	{
		this.codeInfo = codeInfo;
	}
	
	public ModelAndView setCode(HttpServletRequest request, HttpServletResponse response)
	{
		HttpSession session = request.getSession(true);
		
		CodeInfoBean bean = new CodeInfoBean();
		bean.setUserID(session.getAttribute("userId").toString());
		bean.setUserName(session.getAttribute("userName").toString());
		bean.setRoleID(session.getAttribute("roleId").toString());
		bean.setGrpCode(request.getParameter("grpCode"));
		bean.setCode(request.getParameter("code"));
		bean.setDescription(request.getParameter("desc"));
		boolean resultObject = codeInfo.setCode(bean);
		return new ModelAndView("sharedJSP/BooleanResults", "resultObject", resultObject);
	}
	
	public ModelAndView getGrpCode(HttpServletRequest request, HttpServletResponse response)
	{
		HttpSession session = request.getSession(true);
		
		CodeInfoBean bean = new CodeInfoBean();
		bean.setUserID(session.getAttribute("userId").toString());
		bean.setUserName(session.getAttribute("userName").toString());
		bean.setRoleID(session.getAttribute("roleId").toString());
		bean.setGrpCode(request.getParameter("grpCode"));
		List<CodeInfoBean> resultObject = codeInfo.getCode(bean);
		return new ModelAndView("sharedJSP/groupCodeRecords", "resultObject", resultObject);
	}
}
